package com.example.lenovo.myulbumdemo;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yanzhenjie.album.Action;
import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.AlbumFile;

import java.util.ArrayList;

public class ImageActivity extends AppCompatActivity {
    private Button btn_pre;//预览所有图片
    private Button btn_select;//选择照片
    private ImageView iv_show;//需要展示的照片
    private ArrayList<AlbumFile> mAlbumFiles;//


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image);
        btn_pre = findViewById(R.id.btn_pre);
        btn_select = findViewById(R.id.btn_select);
        iv_show = findViewById(R.id.iv_show);

        btn_select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //打开相册并选择
                selectImage();
            }
        });
    }

    private void selectImage() {
        Album.image(ImageActivity.this)
                .multipleChoice()//多选
                .requestCode(200)//
                .camera(true)
                .columnCount(2)//页面列表的列数
                .selectCount(6)//最多可选择的
                .checkedList(mAlbumFiles)
                /*.widget(
                        Widget.newDarkBuilder(this)

                                .build()
                )*/
                .onResult(new Action<ArrayList<AlbumFile>>() {
                    @Override
                    public void onAction(int requestCode, @NonNull ArrayList<AlbumFile> result) {
                        mAlbumFiles = result;
                        Log.e("TAG", "ImageActivity onAction=======()这是啥" + result.size() + "========" + result.get(0).getPath());
                        //将图片加载到imageview当中
                        Album.getAlbumConfig()
                                .getAlbumLoader()
                                .loadAlbumFile(iv_show, result.get(0), iv_show.getWidth(), iv_show.getHeight());


                    }
                })
                .onCancel(new Action<String>() {
                    @Override
                    public void onAction(int requestCode, @NonNull String result) {
                        Log.e("TAG", "取消回掉了。。。。。。");
                    }
                })
                .start();

    }


}
